package com.plugin.helloworld;

import org.gradle.api.Plugin;
import org.gradle.api.Project;

import java.io.File;

public class HelloWorldPlugin implements Plugin<Project> {

    static final String TAG = "任务HelloWorldPlugin:";
    static void println(Object o){
        System.out.println(TAG + o.toString());
    }

    @Override
    public void apply(Project project) {
        project.container(HelloWorldData.class);
        System.out.println("---------------apply FuckTestPlugin--------------");
        File projectParentFile = project.getParent().getProjectDir().getParentFile();
        println("projectParentFile="+projectParentFile.getAbsolutePath());
        //默认创建Task
        //project.getTasks().create("hello", DefaultTask.class);
        //指定创建Task
        HelloWorldTask task = project.getTasks().create("writeHelloTask", HelloWorldTask.class);
        task.setFileName("HelloWorld.txt");
        task.setHelloMan(new HelloWorldData("Jim",19));
        task.setTargetDirectory(projectParentFile);
        task.setGroup("grouphelloworld");
    }
}
